
<head>
<title>SHOP 管理中心 - 品牌管理 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <base href="__STATIC__/hou/">
<link href="styles/general.css" rel="stylesheet" type="text/css" />
<link href="styles/main.css" rel="stylesheet" type="text/css" />
</head>
<body>

<h1>
<span class="action-span"><a href="__URL__/adds">添加品牌</a></span>
<span class="action-span1"><a href="index.php?act=main">SHOP 管理中心</a> </span><span id="search_id" class="action-span1"> - 商品品牌 </span>
<div style="clear:both"></div>
</h1>

<div class="form-div">
  <!--<form action="javascript:search_brand()" name="searchForm">-->
    <img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH">
     <input type="text" name="all" size="15">
    <input type="button" value=" 搜索 " class="button">
  <!--</form>-->
</div>

<form method="post" action="" name="listForm">
<!-- start brand list -->
<div class="list-div" id="listDiv">

  <table cellpadding="3" cellspacing="1">

		<tr>
			<th>品牌名称</th>
			<th>品牌网址</th>
			<th>品牌描述</th>
			<th>排序</th>
			<th>是否显示</th>
			<th>操作</th>
		</tr>
      <tbody id="tbody">
        {foreach $show as $val}
        <tr>
			<td  title="点击修改内容"><span style="float:left"><img src="__ROOT__/uploads/20181102/{$val.brand_logo}" width="16" height="16" border="0" alt="品牌LOGO"></a></span>
                <span class="one">{$val.brand_name}</span><input type="hidden" value="{$val.brand_name}" cid="{$val.brand_id}" class="two"></td>

			<td><a href="http://{$val.site_url}" target="_brank">{$val.site_url}</a></td>
			<td align="left" >{$val.brand_desc}</td>
			<td align="right">{$val.sort}</td>
			<td align="center" class="all" id="{$val.brand_id}" isshow="{$val.is_show}">
                {eq name="val.is_show" value="1"}
                <img src="__STATIC__/hou/images/yes.gif" did="{$val.brand_id}">
                {else/}
                <img src="__STATIC__/hou/images/no.gif" did="{$val.brand_id}">
                {/eq}
            </td>
			<td align="center">
				<a href="__URL__/edit?brand_id={$val.brand_id}" title="编辑">编辑</a> |
				<a href="javascript:;" del="{$val.brand_id}" class="shan">移除</a>
			</td>
		</tr>
        {/foreach}

      <div id="div">
    <tr>
		<td align="right" nowrap="true" colspan="6">
            <div id="turn-page">
			总计  <span id="totalRecords">{$count}</span>个记录
            共 <span id="totalPages">{$sumpage}</span>页
            当前第 <span id="pageCurrent">{$p}</span>页
                每页 <input type="text" size="3" id="pageSize" value="{$size}">条
        <span id="page-link">
          <a href="javascript:;" class="btn" page="1" >第一页</a>
          <a href="javascript:;" class="btn" page="{$last}">上一页</a>
          <a href="javascript:;" class="btn" page="{$next}">下一页</a>
          <a href="javascript:;" class="btn" page="{$sumpage}">尾页</a>
            <select id="xuan">
                {for start="1" end="$sumpage+1"}
                    {eq name='i' value='$p'}
                    <option value="{$i}" selected>{$i}</option>
                    {else/}
                    <option value="{$i}" >{$i}</option>
                    {/eq}
                {/for}
            </select>
        </span>
      </div>
      </td>
    </tr>
      </div>
      </tbody>
  </table>
</div>
</form>
</body>
</html>
<script src="__STATIC__/hou/js/jquery-1.11.1.min.js"></script>
<script>
    var p=1;
    $(document).on('click','.btn,.button',function(){
        var obj=$(this);
        p=obj.attr('page');
        var zhi=$('input[name=all]').val();
        $.ajax({
            url:"{:url('Brand/fenye')}",
            data:{p:p,zhi:zhi},
            dataType:"json",
            type:"get",
            success:function(result){
                if(result.code==1){
                    var str='';
                    ajaxReplace(result);

                }
            },
            error:function(){
                alert('请求错误')
            }
        })
    })
    $('#pageSize').blur(function() {
        var obj=$(this);
        p=obj.attr('page');
        var size = $(this).val();
        $.ajax({
            url: "{:url('Brand/fenye')}",
            data: {p: p, size: size},
            dataType: "json",
            type: "get",
            success: function (result) {
                if(result.code==1) {
                    var str = '';
                    ajaxReplace(result);
                }
            }
        })
    })
    function ajaxReplace(result){
        var str='';
        for(var i=0;i<result.data.show.length;i++) {
            str += " <tr>\
                    <td  title='点击修改内容'><span style='float:left'><img src='__ROOT__/uploads/20181102/" + result.data.show[i].brand_logo +"' width='16' height='16' border='0' \
alt='品牌LOGO'></a></span> <span class='one'>" + result.data.show[i].brand_name + "</span><input type='hidden' value='" + result.data.show[i].brand_name + "' cid='" + result.data.show[i].brand_logo + "' class='two'></td>\
                <td><a href='http:" + result.data.show[i].site_url + "' target='_brank'>" + result.data.show[i].site_url + "</a></td>\
                    <td align='left' >" + result.data.show[i].brand_desc + "</td>\
                    <td align='right'>" + result.data.show[i].sort + "</td>";
                    str+="<td align='center' class='all' id='" + result.data.show[i].brand_id + "' isshow='" + result.data.show[i].is_show + "'>";
                    if(result.data.show[i].is_show==1){
                        str+="<img src='__STATIC__/hou/images/yes.gif'>"
                    }else{
                        str+="<img src='__STATIC__/hou/images/no.gif'></td>"}
            str+="<td align='center'><a href='__URL__/edit?brand_id=" + result.data.show[i].brand_id + "' title='编辑'>编辑</a> |\
                    <a href='javascript:;' del='" + result.data.show[i].brand_id + "' class='shan'>移除</a>\
                    </td>";
       str+=" </tr>";
        }
        str+="<td align='right' nowrap='true' colspan='6'>\
        <div id='turn-page'>\
                总计  <span id='totalRecords'>"+result.data.count+"</span>个记录\
    共 <span id='totalPages'>"+result.data.sumpage+"</span>页\
    当前第 <span id='pageCurrent'>"+result.data.p+"</span>页\
    每页 <input type='text' size='3' id='pageSize' value='"+result.data.size+"'>条\
            <span id='page-link'>\
                <a href='javascript:;' class='btn' page='1' >第一页</a>\
                <a href='javascript:;' class='btn' page='"+result.data.last+"'>上一页</a>\
                <a href='javascript:;' class='btn' page='"+result.data.next+"'>下一页</a>\
                <a href='javascript:;' class='btn' page='"+result.data.sumpage+"'>尾页</a>\
                <select id='xuan'>";
                    for(j=1;j<=result.sumpage;j++){
                        if(j==result.data.p){
                            str+="<option value='"+j+"' selected>"+j+"</option>";
                        }else{
                            str+="<option value='"+j+"'>"+j+"</option>";
                        }
                    }
                        str+="</select> </span> </div> </td>";

            $('#tbody').html(str);
    }

    //删除
    $(document).on('click','.shan',function() {
        if(!confirm('确定要删除吗？')){
            return false;
        }
        var obj=$(this);
        var delid=obj.attr('del');
        $.ajax({
            url:"{:url('Brand/del')}",
            data:{delid:delid},
            dataType:"json",
            type:"get",
            success:function(result){
                if(result.code==1){
                    window.location.reload();
                }
            },
            error:function(){
                alert('请求错误')
            }
        })
    })
    //点击更改状态
    $(document).on('click','.all',function() {
        obj=$(this);
        var id=obj.attr('id');
        var isshow=obj.attr('isshow');
        $.ajax({
            url:"{:url('Brand/saves')}",
            data:{isshow:isshow,id:id},
            dataType:"json",
            type:"get",
            success:function(result){
                if(result.code==1){
                    if(result.isshow==1){
                        obj.replaceWith('<td align="center" class="all" id="'+id+'"  isshow="'+isshow+'"><img src="__STATIC__/hou/images/yes.gif"></td>')
                    }else{
                        obj.replaceWith('<td align="center" class="all" id="'+id+'"  isshow="'+isshow+'"><img src="__STATIC__/hou/images/no.gif"></td>')
                    }
                }
            },
            error:function(){
                alert('请求错误')
            }
        })
    })
    //即点即改
    $('.one').click(function(){
        $(this).hide();
        $(this).next().prop('type','text');
    })
    $('.two').blur(function(){
        var obj=$(this);
        changed=obj.val();
        change=obj.prev().text();
        cid=obj.attr('cid');
        if(change == changed){
            obj.prop('type','hidden');
            obj.prev().show();
            return false;
        }
        if(changed==''){
            alert('请输入品牌名称')
            return false;
        }
        $.ajax({
            url:"{:url('Brand/jdjg')}",
            data:{cid:cid,changed:changed},
            dataType:"json",
            type:"get",
            success:function(result){
                if(result.code==1){
                    obj.prop('type','hidden');
                    obj.prev().show();
                    obj.prev().text(result.data);
                }
            },
            error:function(){
                alert('请求错误')
            }
        })
    })
</script>





<!--
/*data=result['data']['show'];
count=result['data']['count'];sumpage=result['data']['sumpage'];p2=result['data']['p'];size=result['data']['size'];last=result['data']['last'];next=result['data']['next'];
$.each(data,function(i,v){
str+='<tr> <td  title="点击修改内容"><span style="float:left"><img src="__ROOT__/uploads/20181102/'+ v.brand_logo+'" width="16" height="16" border="0" alt="品牌LOGO"></a></span><span class="one">'+ v.brand_name+'</span><input type="hidden" value="'+ v.brand_name+'" cid="'+ v.brand_id+'" class="two"></td><td><a href="http://'+ v.site_url+'" target="_brank">'+ v.site_url+'</a></td><td align="left" >'+ v.brand_desc+'</td><td align="right">{$val.sort}</td><td align="center" class="all" id="'+ v.brand_id+'" isshow="'+ v.is_show+'">';
    if(v['is_show']==1){
    str+='<img src="__STATIC__/hou/images/yes.gif">';
    }else{
    str+='<img src="__STATIC__/hou/images/no.gif">';
    }
    str+='</td><td align="center"><a href="__URL__/edit?brand_id={$val.brand_id}" title="编辑">编辑</a><a href="javascript:;" del="'+ v.brand_id+'" class="shan">移除</a> </td></tr>';
})

str+='<tr><td align="right" nowrap="true" colspan="6"> <div id="turn-page">总计  <span id="totalRecords">'+count+'</span>个记录共 <span id="totalPages">'+sumpage+'</span>页当前第 <span id="pageCurrent">'+p+'</span>页每页 <input type="text" size="3" id="pageSize" value="'+size+'">条 <span id="page-link"> <a href="javascript:;" class="btn" page="1" >第一页</a> <a href="javascript:;" class="btn" page="'+last+'">上一页</a> <a href="javascript:;" class="btn" page="'+next+'">下一页</a> <a href="javascript:;" class="btn" page="'+sumpage+'">尾页</a>';
                    str+=' <select id="xuan">';
        for(i=1;i<=sumpage;i++){
        if(i==p2){
        str+='<option value="'+i+'" selected>'+i+'</option>';
        }else{
        str+='<option value="'+i+'">'+i+'</option>';
        }
        }
        str+='</select> </span> </div> </td> </tr>';
$('#tbody').replaceWith(str);*/

-->
